package com.gitee.candy.other;

import java.util.Arrays;
import java.util.List;

/**
 * @author suYanLong
 * @date 2022年09月22日 16:40
 */
public class StreamJdk8 {

    // https://mp.weixin.qq.com/s/5OljF0lkOo4-z3NXYv_d4w
    public static void main(String[] args) {
        List<String> stringList = Arrays.asList("a", "b", "c");
        System.out.println(stringList.stream().reduce("YY", String::concat));

        List<Integer> integerList = Arrays.asList(1, 3, 4, 6, 5);
        Integer reduce = integerList.stream().reduce(0, (resuslt, num) -> resuslt + num);
        Integer reduce2 = integerList.stream().reduce(0, (resuslt, num) -> resuslt + num, Integer::max);
        System.out.println(reduce);
        System.out.println(reduce2);

        // 全部都匹配/存在任意匹配/不存在匹配
        System.out.println(integerList.stream().anyMatch(s -> s.equals(1)));
        System.out.println(integerList.stream().allMatch(s -> s.equals(1)));
        System.out.println(integerList.stream().noneMatch(s -> s.equals(0)));

    }

}
